<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010 Gio CMS (http://www.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 */

$this->headTitle($this->TRANSLATOR->translator('banner_add_page_title') . ' - ' .
				 $this->TRANSLATOR->translator('about_ad_title') . ' - ' . 
				 $this->TRANSLATOR->translator('common_admin_title', 'core'));
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump', 'core'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('ad_banner_list'); ?>"><?php echo $this->TRANSLATOR->translator('banner_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('banner_add_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body">
			<!--  -->
			<form action="<?php echo $this->url('ad_banner_add'); ?>" method="post" id="adBannerAdd">
				<h4 class="g_a_h4 fl"><?php echo $this->TRANSLATOR->translator('banner_add_guide'); ?></h4>
				<div class="fr">
					<?php if ($this->ACL->isAllowed('add', 'banner', 'ad')) : ?>
					<a class="fl g_a_tip form_submit g_a_submit_button mr5" href="javascript: void(0);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_button_save_title')); ?>"></a>
					<?php endif; ?>
					<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
					<?php if ($this->ACL->isAllowed('list', 'banner', 'ad')) : ?>
					<a class="fl g_a_tip" href="<?php echo $this->url('ad_banner_list'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_list_title')); ?>">
						<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/ad_banner_list_icon.png" style="padding: 0 5px 0 0;" />
					</a>
					<?php endif; ?>
				</div>
				<div class="g_a_line"></div>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_name'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_name_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="banner[name]" id="name" value="<?php if (isset($this->bannerData['name'])) : ?><?php echo $this->bannerData['name']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['name'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['name']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_mode'); ?></label>
					<select class="g_a_tip_right" id="mode" name="banner[mode]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_mode_description')); ?>">
						<option value="unique"<?php if (isset($this->bannerData) && $this->bannerData['mode'] == 'unique') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_mode_unique'); ?></option>
						<option value="share"<?php if (isset($this->bannerData) && $this->bannerData['mode'] == 'share') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_mode_share'); ?></option>
						<option value="alternate"<?php if (isset($this->bannerData) && $this->bannerData['mode'] == 'alternate') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_mode_alternate'); ?></option>
					</select>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_format'); ?></label>
					<select class="g_a_tip_right" id="format" name="banner[format]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_mode_description')); ?>">
						<option value="image"<?php if (isset($this->bannerData) && $this->bannerData['format'] == 'image') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_format_image'); ?></option>
						<option value="flash"<?php if (isset($this->bannerData) && $this->bannerData['format'] == 'flash') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_format_flash'); ?></option>
						<option value="text"<?php if (isset($this->bannerData) && $this->bannerData['format'] == 'text') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_format_text'); ?></option>
						<option value="html"<?php if (isset($this->bannerData) && $this->bannerData['format'] == 'html') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_format_html'); ?></option>
					</select>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_file_url'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_file_url_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="banner[file_url]" id="file_url" value="<?php if (isset($this->bannerData['file_url'])) : ?><?php echo $this->bannerData['file_url']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['file_url'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['file_url']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_html_code'); ?></label>
					<textarea style="width: 400px; height: 100px;" name="banner[html_code]" id="html_code"><?php if (isset($this->bannerData['html_code'])) : ?><?php echo $this->bannerData['html_code']; ?><?php endif; ?></textarea>
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['html_code'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['html_code']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_width'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_width_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="banner[width]" id="width" value="<?php if (isset($this->bannerData['width'])) : ?><?php echo $this->bannerData['width']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['width'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['width']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_height'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_height_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="banner[height]" id="height" value="<?php if (isset($this->bannerData['height'])) : ?><?php echo $this->bannerData['height']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['height'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['height']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_url'); ?></label>
					<input title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_url_description')); ?>" type="text" class="text w_20 g_a_tip_right" name="banner[url]" id="url" value="<?php if (isset($this->bannerData['url'])) : ?><?php echo $this->bannerData['url']; ?><?php endif; ?>" />
					<?php if (isset($this->errorMessages) && isset($this->errorMessages['url'])) : ?>
					<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['url']); ?></span>
					<?php endif; ?>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_status'); ?></label>
					<select class="g_a_tip_right" id="status" name="banner[status]" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_status_description')); ?>">
						<option value="inactive"<?php if (isset($this->bannerData) && $this->bannerData['status'] == 'inactive') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_status_inactive'); ?></option>
						<option value="active"<?php if (isset($this->bannerData) && $this->bannerData['status'] == 'active') : ?> selected="selected"<?php endif; ?>><?php echo $this->TRANSLATOR->translator('banner_status_active'); ?></option>
					</select>
					<br>
				</p>
				<p class="small">&nbsp;</p>
				<p>
					<label for="simple_input"><?php echo $this->TRANSLATOR->translator('banner_page'); ?></label>
				</p>
				<table class="g_a_data_table">
					<tbody>
						<tr id="gAdBannerPageHeader">
							<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_link')); ?>" class="g_a_tip_top w_30"><?php echo $this->TRANSLATOR->translator('banner_link'); ?></th>
							<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('banner_zone')); ?>" class="g_a_tip_top w_20"><?php echo $this->TRANSLATOR->translator('banner_zone'); ?></th>
						</tr>
						<?php if (isset($this->bannerData['items']['route']) && $this->bannerData['items']['route']) : ?>
						<?php foreach ($this->bannerData['items']['route'] as $index => $route) : ?>
						<tr>
							<td>
								<b><?php echo $this->bannerData['items']['title'][$index]; ?></b>
								<div class="g_a_actions buttons_demo" style="margin-top: 5px; display: none;"> 
									<a class="button red" onclick="javascript: $(this).parents('tr').remove();" href="javascript: void(0);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('banner_button_remove_link'); ?></span></a> 
									<div class="clear"></div> 
								</div>
								<input type="hidden" value="<?php echo $this->bannerData['items']['title'][$index]; ?>" name="items[title][]" />	
								<input type="hidden" value="<?php echo $this->bannerData['items']['route'][$index]; ?>" name="items[route][]" />
								<input type="hidden" value="<?php echo $this->bannerData['items']['url'][$index]; ?>" name="items[url][]" />
								<input type="hidden" value="<?php echo $this->bannerData['items']['zone_id'][$index]; ?>" name="items[zone_id][]" />
								<input type="hidden" value="<?php echo $this->bannerData['items']['zone_code'][$index]; ?>" name="items[zone_code][]" />
							</td>
							<td><?php echo $this->bannerData['items']['zone_code'][$index]; ?></td>
						</tr>
						<?php endforeach; ?>
						<?php endif; ?>
						<tr>
							<td><?php echo $this->TRANSLATOR->translator('banner_url'); ?>: <select name="link" id="link" style="width: 200px; display: inline;">
										<option value="">---</option>
										<?php if ($this->pages) : ?>
										<?php foreach ($this->pages as $index => $page) : ?>
										<option value="<?php echo $page['route']; ?>" rel="<?php echo $page['url']; ?>"><?php echo $page['name']; ?></option>
										<?php endforeach; ?>
										<?php endif; ?>
									 </select> 
							<td>
								<?php echo $this->TRANSLATOR->translator('banner_zone'); ?>: <select name="zone" id="zone" style="width: 200px; display: inline;">
											<option value="">---</option>
											<?php if ($this->zones) : ?>
											<?php foreach ($this->zones as $index => $zone) : ?>
											<option value="<?php echo $zone['zone_id']; ?>"><?php echo $zone['code']; ?></option>
											<?php endforeach; ?>
											<?php endif; ?>
										</select>
								<p class="last buttons_demo"> 
									<a href="javascript: void(0);" class="button green" id="gAdBannerAddNewLink"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('banner_button_add_link'); ?></span></a> 
								</p>
							</td>
						</tr>
					</tbody>
				</table>
				<p class="small">&nbsp;</p>
				<p class="last buttons_demo">
					<?php if ($this->ACL->isAllowed('add', 'banner', 'ad')) : ?>
					<a class="button form_submit green" href="<?php echo $this->url('ad_banner_add'); ?>"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('common_submit_button', 'core'); ?></span></a>
					<?php endif; ?>
					<a class="button red" href="javascript: history.go(-1);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_back_button', 'core'); ?></span></a>
				</p>
			</form>
			<!--  -->
			<div class="clear"></div>
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>
<script type="text/javascript">
/**
 * Handle selecting the zone inside Link Provider
 */
function addLink(route, href, title, zone) {
	var tr = $('<tr/>');
	var string = '<b>' + title + '</b>' 
	+ '<br /><b><?php echo $this->TRANSLATOR->translator('banner_page_url'); ?></b>: <input type="text" class="text" value="' + href + '" name="items[url][]" style="width: 200px;" />'
	+ '<div style="margin-top: 5px; display: none;" class="g_a_actions buttons_demo"> <a href="javascript: void(0);" onclick="javascript: $(this).parents(\'tr\').remove();" class="button red"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('banner_button_remove_link'); ?></span></a>   <div class="clear"></div> </div>';
	string += '<input type="hidden" name="items[title][]" value="' + title + '" />';
	string += '<input type="hidden" name="items[route][]" value="' + route + '" />';
	string += '<input type="hidden" name="items[zone_id][]" value="' + zone.id + '" />';
	string += '<input type="hidden" name="items[zone_code][]" value="' + zone.code + '" />';
	
	$('<td/>').html(string).appendTo($(tr));
	$('<td/>').html(zone.name).appendTo($(tr));

	$(tr).hover(function() {
		$(tr).find('div.g_a_actions').show();
	}, function() {
		$(tr).find('div.g_a_actions').hide();
	});
	
	$('#gAdBannerPageHeader').after($(tr));
};

$(document).ready(function() {
	<?php if (($string = $this->MESSENGER->printMessages()) != null) : ?>
	Gio.Message.success('<?php echo $string; ?>');
	<?php endif; ?>

	/**
	 * Create datepicker instances
	 */
	//$('#startDate').datepicker();
	//$('#expiredDate').datepicker();
	
	/**
	 * Switch mode handler
	 */
//	$('#mode').change(function() {
//		if ($(this).val() == 'share') {
//			$('#timeoutContainer').show();
//		} else {
//			$('#timeoutContainer').hide();
//		}		
//	});

	/**
	 * Switch format handler
	 */
//	$('#format').change(function() {
//		$('#fileFormat, #htmlFormat').hide();		
//
//		switch ($(this).val()) {
//			case 'image': 
//			case 'flash':				
//				$('#fileFormat').show();
//				break;
//			case 'text': 
//			case 'html':
//				$('#htmlFormat').show();
//				break;
//		}	
//	});
	
	/**
	 * Add new link
	 */
	$('#gAdBannerAddNewLink').click(function() {
		var route = $('#link').val();
		if (route != '' && $('#zone').val() != '') {
			var href = $('#link').find('option:selected').attr('rel');
			var title = $('#link').find('option:selected').html();
			addLink(route, href, title, {
				id: $('#zone').val(),
				name: $('#zone').find('option:selected').html() 
			});
			$('#link').val('');
		}
	});
});
</script>
